package com.lam.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lam.common.base.controller.BaseController;
import com.lam.common.base.domain.Result;
import com.lam.common.validate.group.Add;
import com.lam.framework.annotation.ParamInject;
import com.lam.framework.operLog.annotation.Log;
import com.lam.framework.operLog.enums.BusinessType;
import com.lam.system.entity.SysDeptUser;
import com.lam.system.param.SysDeptUserParam;
import com.lam.system.service.SysDeptUserService;

/**
 * 组织机构用户Controller
 * 
 * @author admin
 * @date 2022-10-18
 */
@Log(title = "组织机构用户")
@ParamInject
@RestController
@RequestMapping("/${adminPath}/sys/deptUser")
public class SysDeptUserController extends BaseController {

    @Autowired
    private SysDeptUserService sysDeptUserService;

    /**
     * 查询组织机构用户列表
     */
    @Log(oper="分页查询")
    @PreAuthorize("@ss.hasPm('sys:deptUser:list')")
    @GetMapping("/list")
    public Result list(SysDeptUserParam param) {
    
        startPage();
        List<SysDeptUser> list = sysDeptUserService.selectList(param);
        return Result.ok(getTableData(list));
    }

    /**
     * 新增组织机构用户
     */
    @PreAuthorize("@ss.hasPm('sys:deptUser:addByDept')")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/addByDept")
    public Result addByDept(@Validated(Add.class) @RequestBody SysDeptUserParam param) {
    
        return toAjax(sysDeptUserService.saveByDept(param));
    }
    
    /**
     * 删除组织机构用户
     */
    @PreAuthorize("@ss.hasPm('sys:deptUser:removeByDept')")
    @Log(businessType = BusinessType.DELETE)
    @DeleteMapping("/delByDept/{deptId}")
    public Result delByDept(@PathVariable String deptId, @RequestParam(required = true)String userId) {
    
        return toAjax(sysDeptUserService.deleteByDept(deptId, userId));
    }

}
